home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / t3_1 / encore.lha / encore / tsystem / hpassist.c < prev    next >
C/C++ Source or Header  |  1988-03-08  |  3KB  |  137 lines

  1. #include <stdio.h>
  2. #include <signal.h>
  3.  
  4. #define IF ((
  5. #define THEN )?(
  6. #define ELSE ):(
  7. #define FI ))
  8.  
  9. #define MIN_HEAP_SIZE 524288  /* .5 Mb */
  10. #define MAX_HEAP_SIZE 8192000 /* 8 Mb  */
  11. #define DEFAULT_HEAP_SIZE 4096000 /* 4 Mb  */
  12. #define STDIO_SPACE   49152   /* be sure to save 48k of data space for stdio */
  13. #define STATIC_SPACE  131072  /* .125Mb for fun, usr "-l" to add to this */
  14. #define SAVED_SPACE   (STDIO_SPACE+STATIC_SPACE)
  15.  
  16.  
  17. main( argc, argv )
  18. char **argv;
  19. int argc;
  20. {
  21.     long heap_wanted = -1;
  22.     long leave_wanted = -1;
  23.     long debug = 0;
  24.  
  25.     long
  26.     max_heap_size,
  27.     heap_size;
  28.               
  29.     long
  30.     total,
  31.     aligned_total,
  32.     aligned_heap_size;
  33.  
  34.     char **av;
  35.  
  36.     av = argv;
  37.     av[argc] = 0; /* easy end test */
  38.  
  39.     while (*av)  {
  40.     if ( ( !strcmp( *av, "-h" ) ) || ( !strcmp( *av, "-heap" ) ) )
  41.         heap_wanted = IF (!*++av) THEN -2 ELSE atoi( *av ) FI;
  42.     else if ( ( !strcmp( *av, "-l" ) ) || ( !strcmp( *av, "-leave" ) ) )
  43.         leave_wanted = IF (!*++av) THEN -2 ELSE atoi( *av ) FI;
  44.     else if (!strcmp( *av, "-d" ) )
  45.         debug = -1;
  46.     av++;
  47.     }
  48.  
  49.     /* Compute max allowed heap size.  MIN in case datasize is big. */
  50.     /*  Quad align. */
  51.  
  52.     max_heap_size = MAX_HEAP_SIZE;
  53.                    
  54.     /* decide what to allocate - give user his request if it's within reason */
  55.  
  56.     if ((heap_wanted == -2) || (heap_wanted > MAX_HEAP_SIZE))
  57.     heap_size = MAX_HEAP_SIZE;
  58.     else                      
  59.     if (heap_wanted == -1)
  60.     heap_size = DEFAULT_HEAP_SIZE;
  61.     else
  62.     if (heap_wanted > MIN_HEAP_SIZE)
  63.     heap_size = heap_wanted;
  64.     else
  65.     heap_size = MIN_HEAP_SIZE;
  66.  
  67.     total = sbrk( heap_size * 2 );
  68.     if (total == -1)  {
  69.     printf( "T could not allocate two heaps of %d bytes.\n", heap_size);
  70.     printf( "Please retry with smaller heaps by using the -h switch.\n");
  71.     exit(1);
  72.     }
  73.         
  74.     /* make heaps smaller (if necessary) for quadword alignment */
  75.  
  76.     aligned_total = (total + 15) & 0xFFFFFFF0;
  77.     aligned_heap_size = ( ((heap_size * 2) - (aligned_total - total))
  78.               & 0xFFFFFFC0 );
  79.  
  80.     heap_size = aligned_heap_size / 2;
  81.  
  82.     /* print message if any command line flag is given */
  83.  
  84.     if ( (heap_wanted != -1) || (leave_wanted != -1) )
  85.     printf( "%d bytes per heap, %d bytes reserved\n",
  86.         heap_size, leave_wanted + STATIC_SPACE );
  87.  
  88.     start_t( aligned_total, (aligned_total + heap_size), heap_size, 
  89.              argc, argv, debug);
  90.  
  91. }
  92.  
  93. gc_interrupt()
  94. {
  95.   printf("Interrupted during GC; 'q' to exit, anything else to continue GC.\n");
  96.   if (getchar() == 'q')
  97.      exit(0);
  98. }
  99.  
  100. csh()
  101. {
  102.     int status, pid, w;
  103.     register int (*istat)(), (*qstat)();
  104.  
  105.     if ((pid = vfork()) == 0) {
  106.         execl("/bin/csh", "csh", 0);
  107.         _exit(127);
  108.     }
  109.     istat = signal(SIGINT, SIG_IGN);
  110.     qstat = signal(SIGQUIT, SIG_IGN);
  111.     while ((w = wait(&status)) != pid && w != -1)
  112.         ;
  113.     if (w == -1)
  114.         status = -1;
  115.     signal(SIGINT, istat);
  116.     signal(SIGQUIT, qstat);
  117.     return(status);
  118. }
  119.  
  120. extern int errno;
  121. extern char *sys_errlist[];
  122. extern int sys_nerr;
  123.  
  124. get_unix_error_msg(t, size) 
  125. char *t;
  126. int size; 
  127. {
  128.   char *s;    
  129.   int i;
  130.  
  131.   i = 0;
  132.   s = (char *) sys_errlist[ errno ];
  133.   while (i<size && ((*t++ = *s++) != '\0')) i++; 
  134. }
  135.  
  136.  
  137.